package com.ruoyi.rental.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rental.domain.TRental;
import com.ruoyi.rental.service.ITRentalService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 出租房列表Controller
 * 
 * @author ruoyi
 * @date 2025-09-11
 */
@RestController
@RequestMapping("/rental")
public class TRentalController extends BaseController
{
    @Autowired
    private ITRentalService tRentalService;

    /**
     * 查询出租房列表列表
     */
    @RequiresPermissions("rental:rental:list")
    @GetMapping("/list")
    public TableDataInfo list(TRental tRental)
    {
        startPage();
        List<TRental> list = tRentalService.selectTRentalList(tRental);
        return getDataTable(list);
    }

    /**
     * 导出出租房列表列表
     */
    @RequiresPermissions("rental:rental:export")
    @Log(title = "出租房列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRental tRental)
    {
        List<TRental> list = tRentalService.selectTRentalList(tRental);
        ExcelUtil<TRental> util = new ExcelUtil<TRental>(TRental.class);
        util.exportExcel(response, list, "出租房列表数据");
    }

    /**
     * 获取出租房列表详细信息
     */
    @RequiresPermissions("rental:rental:query")
    @GetMapping(value = "/{rentalId}")
    public AjaxResult getInfo(@PathVariable("rentalId") Long rentalId)
    {
        return success(tRentalService.selectTRentalByRentalId(rentalId));
    }

    /**
     * 新增出租房列表
     */
    @RequiresPermissions("rental:rental:add")
    @Log(title = "出租房列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRental tRental)
    {
        return toAjax(tRentalService.insertTRental(tRental));
    }

    /**
     * 修改出租房列表
     */
    @RequiresPermissions("rental:rental:edit")
    @Log(title = "出租房列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRental tRental)
    {
        return toAjax(tRentalService.updateTRental(tRental));
    }

    /**
     * 删除出租房列表
     */
    @RequiresPermissions("rental:rental:remove")
    @Log(title = "出租房列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rentalIds}")
    public AjaxResult remove(@PathVariable Long[] rentalIds)
    {
        return toAjax(tRentalService.deleteTRentalByRentalIds(rentalIds));
    }
}
